package com.yy.permissions_general.module.system.user.service.impl;

import com.yy.permissions_general.module.system.user.entity.UserRole;
import com.yy.permissions_general.module.system.user.mapper.UserRoleMapper;
import com.yy.permissions_general.module.system.user.service.UserRoleService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * <p>
 * 用户角色关联 服务实现类
 * </p>
 *
 * @author YY
 * @since 2021-10-19
 */
@Service
public class UserRoleServiceImpl extends ServiceImpl<UserRoleMapper, UserRole> implements UserRoleService {

    /**
    * 分页查询列表
    * @param userRole
    * @return
    */
    @Override
    public  Page<UserRole>selectPageList(UserRole userRole, int limit, int page)  {
        Page pageContext = new Page(page,limit);
        Page<UserRole> pageList = this.baseMapper.selectPage(pageContext, userRole);
        return pageList;
    }

    /**
    * 新增数据
    * @param userRole
    */
    @Override
    public int addUserRole(UserRole userRole) {
        return baseMapper.insert(userRole);
    }

    /**
    * 修改数据
    * @param userRole
    */
    @Override
    public int editUserRole(UserRole userRole) {
        return baseMapper.updateById(userRole);
    }

    /**
    * 查看详情
    * @param id
    * @return
    */
    @Override
    public UserRole getDetailsById(Integer id) {
        return baseMapper.selectById(id);
    }

    /**
    * 删除数据
    * @param id
    * @return
    */
    @Override
    public int deleteById(Integer id) {
        return baseMapper.deleteById(id);
    }

    /**
    * 批量删除
    * @param ids
    * @return
    */
    @Override
    public int deleteBatch(List<Long> ids) {
        return baseMapper.deleteBatchIds(ids);
    }

    @Override
    public void insertUserRole(int userId, String roleIds) {
        baseMapper.insertUserRole(userId, roleIds);
    }

    @Override
    public int deleteByUserId(Integer userId) {
        Map<String,Object> map = new HashMap<>();
        map.put("user_id",userId);
        return baseMapper.deleteByMap(map);
    }

}

